﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BLL;
using DAL;

namespace QLTTTH
{
    public partial class frmThongTinPhongHoc : DevExpress.XtraEditors.XtraForm
    {
        public frmThongTinPhongHoc()
        {
            InitializeComponent();
        }
        public void FillControl(PhongHoc ph)
        {
            this.txtMaPH.Text = ph.MaPhong.ToString();
            this.txtTenPH.Text = ph.TenPhong;
            this.txtChucNang.Text = ph.ChucNang;
            this.txtTrangThai.Text = ph.TrangThai;
        }
        public void BatNutLuu()
        {
            this.btnLuu.Enabled = true;
        }
        public delegate void SendData(PhongHoc ph);

        public SendData sendData;

        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (sendData != null)
            {
                var vResult = new PhongHocManager().Validate(GetPhongHoc());
                if (vResult.Valid)
                {
                    sendData(GetPhongHoc());
                    DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    XtraMessageBox.Show(vResult.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public PhongHoc GetPhongHoc()
        {
            PhongHoc ph = new PhongHoc();
            if (!txtMaPH.Text.ToString().Equals(""))
            {
                ph.MaPhong = int.Parse(txtMaPH.Text.ToString());
            }
            ph.TenPhong = txtTenPH.Text;
            ph.ChucNang = txtChucNang.Text;
            ph.TrangThai = txtTrangThai.Text;

            return ph;
        }

        private void btnHuyBo_Click(object sender, EventArgs e)
        {
            ResetControl();
            this.Close();
        }
        private void ResetControl()
        {
            this.txtMaPH.ResetText();
            this.txtTenPH.ResetText();
            this.txtChucNang.ResetText();
            this.txtTrangThai.ResetText();
        }
    }
}